use strict;

package Interface;

my $ifXAlias = "1.3.6.1.2.1.31.1.1.1.18";
#my $ifXName = "1.3.6.1.2.1.31.1.1.1.1";
my $ifXName = "1.3.6.1.2.1.2.2.1.2";
my $ifOperStatus = "1.3.6.1.2.1.2.2.1.8";
my $ipAdEntIfIndex = "1.3.6.1.2.1.4.20.1.2";
my $ipAdEntAddr = "1.3.6.1.2.1.4.20.1.1";
my $ipAdEntNetMask = "1.3.6.1.2.1.4.20.1.3";
my $ifPhysAddress = "1.3.6.1.2.1.2.2.1.6";


sub new
{
    my ($class, $ifindex, $ifname, $device) = @_;
    my $this = {
	ifindex => $ifindex,
	device => $device,
	ifname => $ifname,
	ifalias => undef,
	vpn => 0,
	ips => [],
    };
    bless $this, $class;
}

sub print {
    my $this = shift;
    print "[" . $this->{ifindex} . "] - " . $this->{ifname} . " - " . $this->{ifalais} ."\n";
    foreach my $ip (@{$this->{ips}}){
	print "\t" . $ip->addr() . "/" . $ip->mask()  . "\n";
    }
}

sub discover {
    my $this = shift;
    $this->{ifalais} = ::get($this->{device}->{ip}, $this->{device}->{community}, $ifXAlias . "." . $this->{ifindex});
}

sub addIp{
    my ($this, $ip, $mask) = @_;
    my $net = new NetAddr::IP("$ip/$mask");
    push(@{$this->{ips}}, $net);
}

1;
